package com.candoit.webapps.pricing.listeners;

import javax.faces.component.UIComponent;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ValueChangeEvent;
import javax.faces.event.ValueChangeListener;

import com.candoit.webapps.pricing.model.CriterioDistribucion;
import com.candoit.webapps.pricing.util.QueryUtil;

public class ChangeUnidadListener implements ValueChangeListener {

	public void processValueChange(ValueChangeEvent event)
			throws AbortProcessingException {
		UIComponent c = (UIComponent) event.getSource();  
		 String[] ids = c.getId().split("_");
		 Object oldValue = event.getOldValue();
	     Object newValue = event.getNewValue();
	      if (oldValue != newValue)
	        {	
	           String unidad = (String) newValue;   
	           CriterioDistribucion criterio = QueryUtil.getInstance().getCriterioDistribucionById(Integer.valueOf(ids[1]));
	           criterio.setUnidad(unidad);
	        }

	}

}
